{% extends 'layout.html' %}
{% block content %}
     <div class="container">
{#    创建按钮#}
    <div style="margin-bottom: 10px" class="clearfix">
        <a class="btn btn-success" href="/task/add/">
{#            加入图片#}
            <span class="glyphicon glyphicon-plus-sign" aria-hidden="true"></span>
            新建任务
        </a>
        <div style="float: right" class="col-lg-4">
            <form method="get">
                <div class="input-group">
              <input type="text" name='q' class="form-control" placeholder="Search for..."value="{{ search_data }}">
              <span class="input-group-btn">
                <button class="btn btn-default" type="submit">
                    <span class="glyphicon glyphicon-search" aria-hidden="true"></span>
                </button>
             </span>
            </div><!-- /input-group -->
            </form>

        </div><!-- /.col-lg-6 -->
    </div>
{#    用户表格#}
    <div class="panel panel-default">
        <div class="panel-heading">
            <span class="glyphicon glyphicon-th-list" aria-hidden="true"> </span>
            任务列表
        </div>
      <!-- Table -->
      <table class="table table-bordered" >
        <thead>

          <tr>

          <th>ID</th>
              {% for item in form %}
                  <th>{{ item.label }}</th>
              {% endfor %}

          </tr>

        </thead>
        <tbody>
            {% for obj in page_queryset %}
          <tr>
            <td>{{ obj.id }}</td>
            <td>{{ obj.title }}</td>
            <td>{{ obj.get_level_display }}</td>
            <td>{{ obj.detial }}</td>
            <td>{{ obj.user }}</td>



          <td>
               <input  uid="{{ obj.id }}" class="btn btn-primary btn-xs btn-edit" style="width: 35px" type="button " value="编辑">
                <a class="btn btn-danger btn-xs" href="/task/{{ obj.id }}/delete/">删除</a>
            </td>
          </tr>
        {% endfor %}
        </tbody>
      </table>
        </div>
         <div class="clearfix">
             <ul class="pagination" style="float: left">
            {{ page_string }}

        <li><a href="#" aria-label="Next"><span aria-hidden="true">»</span></a></li>
     </ul>
         </div>


    </div>
    </div>
{% endblock %}
{% block js %}
    <script type="text/javascript">
        var edit_id;
        $(function (){
            bindBtnEditEvent();

        });
        function bindBtnEditEvent(){
            $(".btn-edit").click(function (){

                edit_id=$(this).attr("uid");
               $.ajax({
                    url:"/order/edit/",
                    data:{
                        id:edit_id,
                    },
                    type:"get",
                    dataType:"JSON",
                    success:function (res){
                        if(res.status){
                            //把后台传过来的值给标签
                            $.each(res.data,function (name,value){
                                $("#id_"+name).val(value);
                            })
                            //修改新建模态框为编辑字符
                            $("#addForm").text("编辑订单")
                            //打开对话框公用新建模态框
                            $("#myModal").modal('show');
                        }else {
                            alert(res.error)
                        }

                    }
                })

            })

        };
    </script>
{% endblock %}